<template>
    <link rel="stylesheet" href="/layui/css/login.css">
    <div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login" style="display: none;">
        <div class="layadmin-user-login-main">
            <div class="layadmin-user-login-box layadmin-user-login-header">
                <h2><%= projectName %></h2>
                <p><%= description %></p>
            </div>
            <div class="layadmin-user-login-box layadmin-user-login-body layui-form">
                <!--&&htmlchildren&&-->
                <!--&&htmlchildren1&&-->
                <div class="layui-form-item" style="margin-bottom: 20px;">
                    <% if ( leftLink && leftLink.length > 0 ) { %>
                        <a href="<%= leftLink.path %>" style="margin-top: 7px;float: left;" class="layadmin-link"><%= leftLink.title %></a>
                    <% } %>
                    <% if ( rightLink && rightLink.length > 0 ) { %>
                    <a href="<%= rightLink.path %>" class="layadmin-user-jump-change layadmin-link"
                        style="margin-top: 7px;"><%= rightLink.title %></a>
                    <% } %>
                </div>
                <div class="layui-form-item">
                    <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="LAY-user-login-submit"><%= submitText %></button>
                </div>

                <div class="layui-trans layui-form-item layadmin-user-login-other">
                    <% if ( supplier ) { %>
                    <label>社交账号登入</label>
                    <a href="javascript:;"><i class="layui-icon layui-icon-login-qq"></i></a>
                    <a href="javascript:;"><i class="layui-icon layui-icon-login-wechat"></i></a>
                    <a href="javascript:;"><i class="layui-icon layui-icon-login-weibo"></i></a>
                    <% } %>
                </div>
            </div>
        </div>
    </div>
</template>
<script name="compile">
    function templateCompile(data) {
        var defaultData = {
            projectName: "周威-后台管理",
            description: "一个快速生成的后台管理",
            leftLink: false,
            rightLink: false,
            supplier: false,
            type: "module",
            submitText:"登 入",
            md5:false
        };
        var callback = {
            success: true,
            result: Object.assign(defaultData, data)
        };
        if (!data.projectName) {
            return {
                success: false,
                result: "请输入项目名称"
            };
        }
        if (!data.children) {
            return {
                success: false,
                result: "请选择表单模板"
            };
        }
        // if (!data.children1) {
        //     callback.success = false;
        //     callback.result = "请选择提交成功模板";
        // }
        return callback;
    }
</script>
<script name="templateScript">
    form.verify({
        <% verifyList.forEach(function (key) { %>
            <%- key.value %>: function (value, item) { //value：表单的值、item：表单的DOM对象
                <% key.verify.forEach(function (item) { %>
                    if (<%- item.rule %>.test(value)) {
                        return "<%- item.prompt %>";
                    }
                <% }); %>
            },
        <% }); %>
    });
    form.render();
    
    //&&scriptchildren&&
    //提交
    form.on('submit(LAY-user-login-submit)', function (obj) {
        console.log(obj);
        var data = obj.field;
        <% if( md5.langth > 0 ){ %>
            <% md5.forEach(function(item,index){ %>
                data.<%= item %> = md5(data.<%= item %>);
            <% }); %>
        <% } %>
        //&&scriptchildren1&&
    });
</script>